package com.ruoyi.project.datum.view.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.datum.manage.domain.Manage;
import com.ruoyi.project.datum.manage.service.IManageService;
import com.ruoyi.project.datum.view.domain.Photo;
import com.ruoyi.project.datum.view.service.IViewService;
import com.ruoyi.project.system.role.domain.Role;
import com.ruoyi.project.system.user.domain.User;
import io.swagger.models.auth.In;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：查看产品 控制层
 * 时间：2020/5/20
 * 作者：WangHaiDong
 */
@Controller
@RequestMapping("/datum/view")
public class ViewController extends BaseController {

    private String prefix = "datum/view";

    @Autowired
    private IViewService viewService;

    @Autowired
    private IManageService manageService;

    /**
     * 查看产品列表界面
     * @return
     */
    @GetMapping()
    public String datum()
    {
        return  prefix+ "/view";
    }

    /**
     * 条件查询所有的产品信息
     * @param manage
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Manage manage){
        // BaseController 提供的分页
        startPage();
        List<Manage> list = manageService.selectAll(manage);
        return getDataTable(list);
    }

    /**
     * 查看图片库
     */
    @GetMapping("/photoView/{priMesId}")
    public String authUser(@PathVariable("priMesId") Long priMesId, ModelMap mmap)
    {
        mmap.put("priMesId", priMesId);
        return prefix + "/authPhoto";
    }

    /**
     * 查询所有的图片列表
     */
    @PostMapping("/authPhoto/photoList")
    @ResponseBody
    public TableDataInfo allocatedList(Photo photo)
    {
        startPage();
        List<Photo> list = viewService.selectPhotoList(photo);
        return getDataTable(list);
    }

    /**
     * 修改图片显示
     * @param photo
     * @return
     */
    @PostMapping("/authPhoto/changePhoGalShow")
    @ResponseBody
    public AjaxResult changePhoGalShow(Photo photo)
    {
        return toAjax(viewService.changePhoGalShow(photo));
    }


    /**
     * 是否收藏产品信息
     * @param manage
     * @return
     */
    @PostMapping("/changeManageCollect")
    @ResponseBody
    public AjaxResult changeManageCollect(Manage manage)
    {
        return toAjax(viewService.changeManageCollect(manage));
    }



}
